[
	include('/_Makerator/_Library/timer.lasso');
	timer('Custom tags starts to load');
	/*
		"Define"
		
		I am similar to a "Var_Set", but have one very important
		difference: I check to see if the variable I am trying to
		set has already been defined, and I will not over-write it
		if it has.
		
		If, on the other hand, it has not been defined yet, I will
		then set it to the "Default".
		
		Example of use: 
		
		Define: -Name='myVar', -Default='myValue';
	*/
	If: !(Lasso_TagExists: 'Define');
			Define_Tag: 
				'Define',
				-Required='Name',
				-Required='Default'
				;
					If: !(Variable_Defined: #Name);
							Var: #Name = #Default;
					/If;
			/Define_Tag;
	/If;



	
	include('/_Makerator/_Library/_category_ctags.lasso');
	include('/_Makerator/_Library/tag_twitter.lasso');
	include('/_Makerator/_Library/JSON.lasso');
	include('/_Makerator/_Library/tag_string_truncate.lasso');
	include('/_Makerator/_Library/tag_navbar.lasso');
	include('/_Makerator/_Library/tag_mysql_fields.lasso');



	/**
	 * returns an array
	 * requires 'table' and 'column' 
	 * Returns an array of the possible values for a SET
	
	use like:
		
		get_set_options('Table_Name', 'Column_Name');

	 */
	if(!lasso_tagExists('get_set_options'));
		define_tag(
			'get_set_options', 
			-required='table', 
			-required='column', 
			-priority='replace'
			);
				local('sql' = 'SHOW COLUMNS FROM ' #table ' LIKE "'#column'"');
				inline(
					$connection_db, 
					-table=#table, 
					-sql=#sql
					);
						rows;
							return(column('Type')->
								substring(
										5, 
										(column('Type')->length - 5)
									)->split(',')
								);
						/rows;
				/inline;
		/define_tag;
	/if;

	if(!lasso_tagExists('get_column_default'));
		define_tag(
			'get_column_default', 
			-required='table', 
			-required='column', 
			-priority='replace'
			);
				local('sql' = 'SHOW COLUMNS FROM ' #table ' LIKE "'#column'"');
				inline(
					$connection_db, 
					-table=#table, 
					-sql=#sql
					);
						rows;
							return(column('Default'));
						/rows;
				/inline;
		/define_tag;
	/if;




/*----------------------------------------------------------------------------

[xml_tree]
Extends and simplifies the built-in XML type.

Author: Jason Huck
Last Modified: Jun. 01, 2006
License: Artistic license <http://opensource.org/licenses/artistic-license.php>

Description:
This type provides additional functionality for the built-in XML type, making 
it easier to retrieve values from XML documents when the structure is known. 
It adds the following new member tags:

->atts - Returns a map of the attributes for the current node, instead of an 
array of pairs.

->attribute(string) - Returns the value of the given attribute for the current 
node.

->nodename(index) - Returns the given child node by name. If there are 
multiple nodes of the same name, you can return a specific node by passing an 
index. If no matching child nodes are found, it will look for an attribute by 
that name.

->getnode(string) - Same as ->nodename above. Useful if the node name 
conflicts with an existing member tag, such as "name."

->getnodes - Returns the children of the current node, minus the empty ones 
that ->children generates on its own.


Sample Usage:
var('testxml') = '\
<?xml version="1.0" ?>
<root>
	<record>
		<thing foo="bar">blah</thing>
		<thing foo="meow">moo</thing>
	</record>
</root>';

var('test') = xml_tree($testxml);

$test->record->thing(2)->contents;

-> moo




Downloaded from tagSwap.net on Jun. 04, 2006.
Latest version available from <http://tagSwap.net/xml_tree>.

----------------------------------------------------------------------------*/
		

define_type(
	'tree', 'xml',
	-namespace='xml_',
	-description='Extends and simplifies the built-in XML type.'
);
	define_tag('atts');
		local('out' = map);
		
		iterate(self->attributes, local('i'));
			#out->insert(@#i->first = @#i->second);
		/iterate;
		
		return(@#out);
	/define_tag;
	
	define_tag('attribute', -req='name');
		if(self->attributes->size && self->attributes->find(#name)->size);
		 	return(@self->attributes->find(#name)->first->second);
		else;
			return('');
		/if;
	/define_tag;
	
	define_tag('getNode', -req='nodename', -opt='count');
		local('matches' = array);
		
		iterate(self->children, local('i'));
			#i->name == #nodename ? #matches->insert(@#i);
		/iterate;
		
		if(!#matches->size);
			return(@self->attribute(#nodename));
		else(#matches->size == 1);
			return(@#matches->first);
		else;
			if(local_defined('count'));
				protect;
					return(@#matches->get(integer(#count)));
					
					handle_error;
						return;
					/handle_error;
				/protect;
			else;
				return(@#matches);
			/if;
		/if;
	/define_tag;
	
	define_tag('getnodes');
		local('out') = @self->children;
		
		iterate(#out, local('i'));
			string(#i)->iswhitespace ? #out->remove(loop_count);
		/iterate;
		
		return(@#out);
	/define_tag;
	
	define_tag('_unknowntag');
		if(params->size);
			return(@self->getnode(tag_name, @params->first));
		else;
			return(@self->getnode(tag_name));
		/if;
	/define_tag;
/define_type;







	var: 'Makerator_ValidationKeys' = (array);
	var: 'Makerator_ValidationTags' = (map);
	
	
	
	
	/*
		       datatype: compares the submitted value against the rules allowed for each of the various datatypes
		        returns: true | false
		         inputs: alpha | alphanumeric | date | decimal | email | integer | numeric | phone | ssn | url
		   TO DO inputs: datetime | ip | ipv6 | time | zip | zipPlus4 | creditCard
	*/
	var: 'Makerator_ValidDataTypes' = 
		array(
			'Alpha',
			'AlphaNumeric',
			'Date',
			'Decimal',
			'Email',
			'Integer',
			'Numeric',
			'Phone',
			'SSN',
			'URL',
			)
		;


	iterate: $Makerator_ValidDataTypes, local: 'a_datatype';
			$Makerator_ValidationKeys->insert(#a_datatype);
	/iterate;




]